{{#section 'style'}}<link rel="stylesheet" href="/style/center.css">{{/section}}

<div class="techbook favorite">
    <!--head-->
    {{> header_center}}
    <!--head End-->

    <!--body-->
    <div class="body">
        <div class="wrap">

            <h3 class="title">商品收藏</h3>
            <div class="del" id="delBox">
                <input type="checkbox" name="" id="del"><label for="del">全选</label><span>删除</span>
            </div>
            <div class="historyList">

                {{#each books}}
                    <dl data-sku="{{this.sku}}">
                        <dt><a href="/item/{{this.sku}}"><img src="/uploads/previews/{{this.img}}" alt=""/></a></dt>
                        <dd>
                            <div class="sale"><b>￥{{this.price}}</b>&nbsp;<s>￥{{this.market}}</s></div>
                            <span>加入购物车</span>
                            <i></i>
                        </dd>
                    </dl>
                {{/each}}

            </div>

            <div class="cb"></div>

            {{>page}}

        </div>
    </div>
    <!--body End-->

    <!--foot-->
    {{>footer}}
    <!--foot End-->

</div>

{{#section 'script'}}
    <script>
        $(function(){
            var $list=$('.historyList');

            //“商品收藏”单个删除
            $list.on('click','i', function () {
                var $dl=$(this).closest('dl');
                $dl.hide(200, function () {
                    $dl.remove();
                });
                $.ajax({
                    url:'favorite',
                    type:'DELETE',
                    data:{
                        user_id:'{{user._id}}',
                        sku:$(this).closest('dl').data('sku')
                    }
                });
            });

            //批量删除
            var $delBox=$('#delBox');
            $delBox.on('click','span', function () {
                if($delBox.find('input').prop('checked')){
                    $list.hide(200, function () {
                        $list.remove();
                    });
                    var skus=[];
                    $list.find('dl').each(function(i,dl){
                        skus.push($(dl).data('sku'));
                    });

                    console.log('skus:',skus);

                    $.ajax({
                        url:'favorite',
                        type:'DELETE',
                        data:{
                            user_id:'{{user._id}}',
                            skus:skus
                        }
                    });
                }
            });
        });
    </script>
{{/section}}